package com.example.my_flea_street.Mapper;

import com.example.my_flea_street.bean.ReportedInfo;
import com.example.my_flea_street.bean.ReportedUser;
import com.example.my_flea_street.bean.SearchUser;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface AdministratorMapper {
    @Insert("insert into notice(time,text) values(#{time},#{text})")
    @Options(useGeneratedKeys = true)
    void postNotice(@Param("time") String time,@Param("text") String text);

    @Select("SELECT b.id ,b.release_time,b.text,b.pic,b.user_id,a.name,a.head FROM user a,is_repored_user b WHERE a.id=b.user_id ORDER BY release_time")
    Page<ReportedUser> getInfo();

    @Update("update user set banded=#{type} where id=#{user_id}")
    void banUser(@Param("user_id") int user_id, @Param("type") int type);

    @Delete("delete from is_repored_user where id=#{id}")
    void cancel(@Param("id") int id);

    @Select("SELECT b.id ,b.release_time,b.info_id,a.category,a.pic,a.text,a.key_word FROM information a,is_reported_info b WHERE a.id=b.info_id ORDER BY b.release_time")
    Page<ReportedInfo> getReportedInfo();

    @Delete("delete from information where id=#{info_id}")
    void deleteInfo(@Param("info_id") int info_id);

    @Select("select pic from information where id=#{id}")
    String getPic(@Param("id") int id);

    @Delete("delete from is_reported_info where id=#{id}")
    void cancelInfo(int id);

    @Select("select id,head,name,introduction from user where banded=1")
    Page<SearchUser> getBandedUser();
}
